package com.example.azheng.rxjavamvpdemo.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author azheng
 * @date 2018/4/24.
 * GitHub：https://github.com/RookieExaminer
 * Email：wei.azheng@foxmail.com
 * Description：
 */
public abstract class BaseActivity extends AppCompatActivity {

    public Context context = this;
    private Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(this.getLayoutId());
        unbinder = ButterKnife.bind(this);
        initView();
    }

    @Override
    protected void onDestroy() {
        unbinder.unbind();
        super.onDestroy();
    }

    /**
     * 设置布局
     *
     * @return
     */
    public abstract int getLayoutId();

    /**
     * 初始化视图
     */
    public abstract void initView();


    /**
     * @param s
     */
    public void showToast(String s) {
        try {
            Toast.makeText(context, s, Toast.LENGTH_LONG).show();
        }catch (Exception e){}
    }
    public void doActivity(Class<?> c) {
        Intent intent = new Intent(this, c);
        startActivity(intent);
    }

    public void doActivity(Class<?> c, String tag, String content) {
        Intent intent = new Intent(this, c);
        intent.putExtra(tag, content);
        startActivity(intent);
    }
}
